// pages/card/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    back:0,
    listData:[],
    cardInfo: {},
    empty:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
  
    app.getUserInfo(function(user_info){
      // that.loadList();
      that.data.user_info = user_info;
      console.log("user_info",user_info);
    })
    
     
  },
  // loadList: function (reload) {
  //   var that = this;
  //   if (reload == 1) {
  //     this.setData({
  //       loading: 0,
  //       listData: [],
  //     });
  //   }
  //   if (this.data.loading == 1 ) {
  //     return;
  //   }
  //   this.data.loading = 1;
  //   app.api("api/wechat_tool/getcardlist", {
  //     shop_id : this.data.shop_id,
  //   }, function (res) {
  //     that.data.loading = 0;
  //     if (res.code != 200) {
  //       app.alert(res.msg);
  //       return;
  //     }
  //     if (res.data.length==0){
  //       that.setData({ empty:1});
  //     }else{
  //       that.setData({ empty: 0});
  //     }

  //     that.setData({
  //       listData: res.data,
  //     });
  //   })

  // },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
     
  },



  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.loadList(1);
    my.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },


  /**
  **
    * 用户点击右上角分享
    */
  onShareAppMessage: function (res) {
    var that = this;
    this.btn_cancel();
    if (res.from === 'button') {
      // 来自页面内转发按钮
      console.log(res.target)
    }
    var title = this.data.user_info.nickname + "分享了一张[" + that.data.cardInfo.name + "]优惠券,快来领取吧";
    return {
      title: title,
      path: '/pages/card/info?cardId=' + that.data.cardInfo.cardId + '&p_user_id=' + this.data.user_info.user_id,
      success: function (res) {
        // 转发成功
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  btn_cancel: function () {
    this.setData({ popup: 0 });
  },
  showShare: function (e) {
    var idx = e.currentTarget.dataset.idx;
    this.data.cardInfo = this.data.listData[idx].cardInfo;
    this.setData({ popup: 1 });
  },
  makePic: function () {
    my.navigateTo({
      url: '/pages/draw/index?page=' + encodeURIComponent('pages/card/info') + '&scene=' + this.data.cardId + '_' + this.data.user_info.user_id + "&title=" + encodeURIComponent(this.data.cardInfo.name) + "&picname=" + encodeURIComponent(this.data.cardInfo.pic),
    })
  }
})